/*
 * Copyright (c) $today.year-Now http://www.zxpnet.com All rights reserved.
 */

package com.zxp.common.core.util;

import cn.hutool.core.util.StrUtil;

/**
 * 代码生成器的辅助类
 *
 * @desc:
 * @author: shollin
 * @date: 2021/6/17/017 13:38
 */
public class CodegenHelper {

    /**
     * 首字母大写
     * @param str
     * @return
     */
    public static String getClassName(String str) {
        return StrUtil.upperFirst(str);
    }

    /**
     * 去掉表名前缀
     * @param tableName
     * @return
     */
    public static String getTableName2(String tableName) {

        tableName = tableName.toLowerCase();//全部转换为小写
        int index = tableName.indexOf("_");//下划线的位置
        if (index == -1) {
            return tableName;
        }
        String name = tableName.substring(index + 1);//从下划线开始截取

        return getColumnName2(name);//去掉下划线
    }


    /**
     * 驼峰处理
     * @param
     * @return
     */
    public static String getColumnName2(String name) {
        while (true) {
            int i = name.indexOf("_");//取下划线
            System.out.println("i=" + i);
            if (i == -1) {
                break;//跳出
            }
            String n = name.substring(i + 1, i + 2).toUpperCase();//取出需要转换的字母进行转换
            name = name.substring(0, i) + n + name.substring(i + 2);
        }
        return name;
    }

}
